﻿using System;
using System.ServiceModel.Activation;

namespace Prompts.Service.PromptService
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class PromptService : IPromptService
    {
        private readonly IBaseReportParameterService _baseReportParameterService;
        private readonly IBaseReportInterpreter<PromptInfo> _baseReportInterpreter;

        public PromptService(IBaseReportParameterService baseReportParameterService, IBaseReportInterpreter<PromptInfo> baseReportInterpreter)
        {
            _baseReportInterpreter = baseReportInterpreter;
            _baseReportParameterService = baseReportParameterService;
        }

        public GetPromptsResponse GetPromptsForReport(string path)
        {
            try
            {
                var baseReportParameters = _baseReportParameterService.GetParametersFor(path);
                var prompts = _baseReportInterpreter.Get(baseReportParameters);
                return new GetPromptsResponse(prompts, false, string.Empty);
            }
            catch (Exception e)
            {
                return new GetPromptsResponse(new PromptInfo[]{}, true, e.Message);
            }
        }
    }
}
